package com.sservice.service.service.impl;

import com.sservice.common.Constants;
import com.sservice.service.service.IUserService;
import com.sservice.urp.dao.IUserDao;
import com.sservice.urp.dao.IUserRoleDao;
import com.sservice.urp.entity.User;
import com.sservice.urp.entity.UserRole;
import com.sservice.urp.vo.UserVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Service
public class UserServiceImpl implements IUserService {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public UserVo getLoginedUser(HttpServletRequest request) {
        return (UserVo)request.getSession().getAttribute(Constants.USER);
    }

    @Autowired
    private IUserDao userDao;
    //
    @Autowired
    private IUserRoleDao userRoleDao;


    @Override
    public boolean isShiAdminLevel(User u) {
        return (Constants.SHI_ID.equals(String.valueOf(u.getComid())));
    }

    @Override
    public boolean isShiAdminLevel(UserVo u) {
        return (Constants.SHI_ID.equals(String.valueOf(u.getComid())));
    }

    @Override
    public boolean isShiAdminLevel(String comId) {
        return Constants.SHI_ID.equals(comId);
    }

    @Override
    public List<User> queryPlainByPage(UserVo user) {
        return userDao.queryPlainByPage(user);
    }

    @Override
    public int countPlainByPage(UserVo user) {
        return userDao.countPlainByPage(user);
    }

    @Override
    public List<User> queryByPage(UserVo user) {
        return userDao.queryByPage(user);
    }

    @Override
    public int countByPage(UserVo user) {
        return userDao.countByPage(user);
    }

    @Override
    public User queryUserByPhone(String phone) {
        logger.info("service方法进入----");

        return userDao.queryByPhone(phone);
    }

    @Override
    public UserVo queryUserByPhoneOrUserName(User user) {
        UserVo uv = userDao.queryUserByPhoneOrUserName(user); //||
        return uv;
    }


    @Override
    public int deleteByPrimaryKey(Integer id) {
        return userDao.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(User record) {
        return userDao.insert(record);
    }

    @Override
    public int insertSelective(User record) {
        return userDao.insertSelective(record);
    }

    @Override
    public User selectByPrimaryKey(Integer id) {
        return userDao.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(User record) {
        return userDao.updateByPrimaryKeySelective(record);
    }

    @Override
    public int deleteByUserId(Integer userid) {
        return userRoleDao.deleteByUserId(userid);
    }

    @Override
    public int addBatch(List<UserRole> list) {
        return userRoleDao.addBatch(list);
    }

    @Override
    public User selectDepByPrimaryKey(User record) {
        return userDao.selectDepByPrimaryKey(record);
    }


    @Override
    public int queryCount(UserVo user) {
        return userDao.queryCount(user);
    }

    @Override
    public int queryCountByComId(UserVo user) {
        return userDao.queryCountByComId(user);
    }

    @Override
    public int queryCountByDepId(UserVo user) {
        return userDao.queryCountByDepId(user);
    }

    @Override
    public List<UserVo> queryPlainWithDr(UserVo user) {
        return userDao.queryPlainWithDr(user);
    }

    @Override
    public int countPlainWithDr(UserVo user) {
        return userDao.countPlainWithDr(user);
    }
}
